package com.shopReduce.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.shopReduce.bean.UserShopReduce;
import com.shopReduce.service.IUserShopReduceService;

import shopBean.common.bean.RestResult;
import shopBean.common.responseCode.Status;
import shopBean.common.utils.DateCommonUtils;
import shopBean.common.utils.RestResultGenerator;

import java.text.ParseException;

@RestController
@RequestMapping("userShopReduce")
public class UserShopReduceController {

	
	@Autowired
	IUserShopReduceService userShopReduceService;
	
	@RequestMapping("/insert")
	public RestResult insert(UserShopReduce userShopReduce) throws ParseException {

		if(StringUtils.isBlank(userShopReduce.getUserId())){
			return RestResultGenerator.genErrorResult("用户id不能为空",null, Status.userId_is_empty);
		}
		if(StringUtils.isBlank(userShopReduce.getShopReduceId())){
			return RestResultGenerator.genErrorResult("商品优惠券id不能为空",null,Status.shopreduce_is_empty);
		}

		return userShopReduceService.insert(userShopReduce);
	}
	
	@RequestMapping("/delete")
	public RestResult delete(String shopReduceId,String userId) {
		return RestResultGenerator.genSuccessResult(userShopReduceService.deleteByUserIdAndShopReduceId(shopReduceId, userId));
	}
	
	@RequestMapping("/getByShopReduceIdAndUserId")
	public RestResult getByShopReduceIdAndUserId(String shopReduceId,String userId) {
		return RestResultGenerator.genSuccessResult(userShopReduceService.getByUserIdAndShopReduceId(shopReduceId, userId));
	}
	public static void main(String[] args) throws ParseException {

		System.out.print(DateCommonUtils.getDate("2018-07-22 11:11:11.0"));
	}
}
